//学员来源信息查询

<template>
  <div>
    <div v-if="see">
      <div>
        <!-- 查询搜索框 -->
        <span style="display:inline-block; ">
          <el-form :inline="true" :model="selectfrom" class="demo-form-inline">
            <el-form-item label="来源">
              <el-input
                v-model="selectfrom.school"
                placeholder="学校"
                style="width:300px"
                clearable
              ></el-input>
            </el-form-item>
            <el-form-item>
              <el-button type="primary" @click="schoolselect(selectfrom.school)"
                >来源查询</el-button
              >
            </el-form-item>
          </el-form>
        </span>
        <span style="display:inline-block; ">
          <el-form :inline="true" :model="selectfrom" class="demo-form-inline">
            <el-form-item>
              <el-button type="primary" plain @click="nameselect()"
                >模糊查询</el-button
              >
            </el-form-item>
          </el-form>
        </span>
        <span style="display:inline-block; ">
          <el-form :inline="true" :model="selectfrom" class="demo-form-inline">
            <el-form-item>
              <el-button type="primary" plain @click="classselect()"
                >班级查询</el-button
              >
            </el-form-item>
          </el-form>
        </span>
        <el-pagination
          style="display:inline-block; "
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="currentPage"
          :page-sizes="[5, 10, 20, 40]"
          :page-size="pagesize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="studentselect.length"
        >
        </el-pagination>
      </div>
      <div>
        <!-- 查询完的表格 -->
        <el-table
          :data="
            studentselect.slice(
              (currentPage - 1) * pagesize,
              currentPage * pagesize
            )
          "
          stripe
          style="width: 100%"
          height="580"
        >
          <el-table-column prop="name" label="姓名" width="180">
          </el-table-column>
          <el-table-column prop="sex" label="性别" width="180">
          </el-table-column>
          <el-table-column prop="status" label="状态" width="180">
          </el-table-column>
          <el-table-column prop="school" label="来源" width="180">
          </el-table-column>
          <el-table-column prop="tele" label="电话" width="180">
          </el-table-column>
          <el-table-column prop="date" label="生日" width="180">
          </el-table-column>
          <el-table-column prop="" label="操作" width="180" fixed="right">
            <template slot-scope="scope">
              <el-button
                icon="el-icon-search"
                type="text"
                @click="cx(scope.row.sid)"
                ><i class="el-icon-edit">查看详情并编辑</i></el-button
              >
            </template>
          </el-table-column>
        </el-table>
      </div>
    </div>
    <div v-if="seen">
      <!-- 个人页 -->
      <el-button style="float:right" type="primary" @click="qx"
        >取消并返回</el-button
      >
      <!-- <el-button type="primary" @click="qx">取消</el-button> -->
      <el-form
        ref="student"
        :model="student"
        label-width="50%"
        style="clear:both;"
        :rules="rules"
      >
        <div style="width:800px">
          <el-form-item label="姓名">
            <el-input v-model="student.name"></el-input>
          </el-form-item>
          <el-form-item label="性别">
            <el-select v-model="student.sex">
              <el-option label="男" value="男"></el-option>
              <el-option label="女" value="女"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="电话" prop="tele">
            <el-input v-model="student.tele"></el-input>
          </el-form-item>
          <el-form-item label="生日">
            <el-date-picker
              type="date"
              placeholder="选择日期"
              v-model="student.date"
            ></el-date-picker>
          </el-form-item>
          <el-form-item label="地址">
            <el-input v-model="student.address"></el-input>
          </el-form-item>
          <el-form-item label="学校">
            <el-input v-model="student.school"></el-input>
          </el-form-item>
          <el-form-item label="专业">
            <el-input v-model="student.speciality"></el-input>
          </el-form-item>
          <!-- <el-form-item label="学生id">
                            <el-input v-model="student.sid"></el-input>
                        </el-form-item> -->
          <!-- <el-form-item label="班主任">
                        <el-input v-model="student.headmaster"></el-input>
                    </el-form-item> -->
          <el-form-item label="缴费方式">
            <!--费方式（分期0、全款1）  -->
            <el-select v-model="student.payway">
              <el-option label="分期" value="0"></el-option>
              <el-option label="全款" value="1"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="状态">
            <!-- 状态（在读1、离校0、试听-1） -->
            <el-select v-model="student.status">
              <el-option label="在读" value="0"></el-option>
              <el-option label="离校" value="1"></el-option>
              <el-option label="试听" value="-1"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="班级名">
            <el-select v-model="student.classname">
              <el-option label="王者班" value="王者班"></el-option>
              <el-option label="荣耀班" value="荣耀班"></el-option>
              <el-option label="英雄班" value="英雄班"></el-option>
              <el-option label="联盟班" value="联盟班"></el-option>
            </el-select>
          </el-form-item>
          <!-- <el-form-item label="班级ID">
                            <el-input v-model="student.cid"></el-input>
                        </el-form-item> -->

          <el-form-item style="width:970px">
            <el-button type="primary" @click="update('student')"
              >立即修改</el-button
            >

            <el-button type="primary" @click="qx">取消</el-button>
          </el-form-item>
        </div>
      </el-form>
    </div>
  </div>
</template>
<script>
export default {
  name: "stusource",
  inject: ["reload"],
  data() {
    return {
      rules: {
        tele: [
          { required: true, message: "请输入电话号码", trigger: "blur" },
          { pattern: /^1[3578]\d{9}$/, message: "手机号码不合法" },
        ],
      },
      form: [],
      selectfrom: {
        name: "",
        sex: "",
        classname: "",
        school: "",
      },
      currentPage: 1, //初始页
      pagesize: 10, //    每页的数据
      studentselect: [],
      student: [],
      see: true,
      seen: false,
    };
  },

  methods: {
    // 初始页currentPage、初始每页数据数pagesize和数据data
    handleSizeChange: function(size) {
      this.pagesize = size;
      console.log(this.pagesize); //每页下拉显示数据
    },
    handleCurrentChange: function(currentPage) {
      this.currentPage = currentPage;
      console.log(this.currentPage); //点击第几页
    },
    nameselect: function() {
      this.$router.push({ name: "stubasic" }).catch((err) => err);
    },
    classselect: function() {
      this.$router.push({ name: "stuclass" }).catch((err) => err);
    },
    schoolselect: function(school, asd) {
      console.log(school);
      var that = this;
      this.axios({
        method: "post",
        url: "http://192.168.2.225:8080/com.huidian.rem/Sourse",
        headers: { "Content-Type": "application/x-www-form-urlencoded" },
        data: JSON.stringify({
          school: school,
        }),
      })
        .then((res) => {
          console.log(res.data);
          console.log("dadasdas");
          res.data.forEach((element) => {
            element.status =
              element.status == 1
                ? "在读"
                : element.status == 0
                ? "离校"
                : "试听";
            element.payway = element.payway == 0 ? "分期" : "全款";
          });
          that.studentselect = res.data;
          if (asd != 2) {
            that.$message.success("查找成功");
          }
          // this.reload();
        })
        .catch((error) => {
          if (fsh != 5) {
            return;
          }
          console.log(error);
          console.log("错误");
          that.$message.error("查找失败");
        });
    },
    cx: function(sid) {
      // console.log('“啊啊啊');
      // console.log(sid)
      this.axios({
        method: "post",
        url: "http://192.168.2.225:8080/com.huidian.rem/FindoneStudent",
        headers: { "Content-Type": "application/x-www-form-urlencoded" },
        data: JSON.stringify({
          sid,
        }),
      })
        .then((res) => {
          console.log(res);
          console.log("aaaaaaaaaaa");
          // console.log(res.data.payway);
          var aaa = res.data;
          aaa.payway = aaa.payway == 0 ? "分期" : "全款";
          //  <!-- 状态（在读1、离校0、试听-1）
          aaa.status =
            aaa.status == 1 ? "在读" : aaa.status == 0 ? "离校" : "试听";
          // console.log(aaa.status);
          var that = this;
          that.student = res.data;
          console.log(that.student);
          that.see = false;
          that.seen = true;
        })
        .catch((error) => {
          console.log(error);
        });
    },
    qx: function() {
      var that = this;
      that.see = true;
      that.seen = false;
    },
    update: function(formName) {
      // console.log("修改惺惺惜惺惺")
      var that = this;
      // console.log(that.student);
      var s = that.student;

      s.payway = s.payway == "分期" ? 0 : 1;
      //  <!-- 状态（在读1、离校0、试听-1）
      s.status = s.status == "在读" ? 1 : s.status == "离校" ? 0 : -1;

      var address = s.address;
      var cid = s.cid;
      var classname = s.classname;
      var date = s.date;
      // var headmaster = s.headmaster;
      var name = s.name;
      var payway = s.payway;
      var school = s.school;
      var sex = s.sex;
      var sid = s.sid;
      var speciality = s.speciality;
      var status = s.status;
      var tele = s.tele;
      console.log(that.student);
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.axios({
            method: "post",
            url: "http://192.168.2.225:8080/com.huidian.rem/UpdateStudent",
            headers: { "Content-Type": "application/x-www-form-urlencoded" },
            data: JSON.stringify({
              address: address,
              cid: cid,
              classname: classname,
              birth: date,
              // headmaster: headmaster,
              name: name,
              payway: payway,
              school: school,
              gender: sex,
              sid: sid,
              speciality: speciality,
              status: status,
              tel: tele,
            }),
          }).then((res) => {
            // console.log('xxx');
            // console.log(res);
            // 刷新页面
            // this.reload()
            var that = this;
            that.schoolselect(that.selectfrom.school, 2);

            that.see = true;
            that.seen = false;

            that.$message.success("修改成功");
          });
          // .catch(error => {
          //     console.log(error);
          //     console.log('错误');
          //     that.$message.error('修改失败');
          // });
        } else {
          // that.$message.warning('手机号错了呢')
          var that = this;
          var aaa = that.student;
          aaa.payway = aaa.payway == 0 ? "分期" : "全款";
          //  <!-- 状态（在读1、离校0、试听-1）
          aaa.status =
            aaa.status == 1 ? "在读" : aaa.status == 0 ? "离校" : "试听";
          that.$message.warning("Σσ(・Д・；)我我我什么都没做!!!");
          return false;
        }
      });
    },
  },
};
</script>
<style scoped></style>
